From patchwork Mon Jul 12 23:05:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12372539 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,URIBL_BLOCKED,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 C0639C07E99 for ; Mon, 12 Jul 2021 23:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 989DC60FE7 for ; Mon, 12 Jul 2021 23:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbhGLXKa (ORCPT ); Mon, 12 Jul 2021 19:10:30 -0400 Received: from mail-ed1-f51.google.com ([209.85.208.51]:46957 "EHLO mail-ed1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbhGLXKa (ORCPT ); Mon, 12 Jul 2021 19:10:30 -0400 Received: by mail-ed1-f51.google.com with SMTP id s15so30381070edt.13; Mon, 12 Jul 2021 16:07:39 -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=5pjMesyq1pHdjXnthdtuE3bdQ3vGQE2JW/5oUX1BQXU=; b=YSVW5/xI8ofU59jvslGKgFWkYUgAm1kQPUlr1BISdsSrizDOAQlx/IB7njkbfvIbe+ CIZ+MnRG7NVHlEkBZXKCLSC37tyAud+8sTnEUbYErvKR7LKw2XZ4ulOLwxHcnzRgAE1S ULMgCYYzV6wZBYWnAajlLjtkdGQUj4KDtWqcPGO0AnFF8AMfrxdEjOArCZ0GfzCDQzdN pORaCHkAyYgsqUWhXcS5iYTiq+nQsZK7ZVA7neXAZz3EM0M0gFeJgRb8T1UBYiUZQIvk lbHHEcnsA3DEIDj3Wb9jdVVxGfMT9i3H3NiXkEsVvd0on5L9h+hEktLJL1668HdJNtka T/Yw== X-Gm-Message-State: AOAM530JGs4o7S1KQRwJV636WCyRv1QlQGA3yr0eWFfAfsIGvHdnWXzq Oh+1U8WqFU5AaPXgmpvgfgZ1rnGZHezhrg== X-Google-Smtp-Source: ABdhPJzRs8hZEOn5FeEYmqrhp/UfboiOSx2r9fFxULoGASfYLNNoR2jZYMJ2ABprpIWpuLAz7ImTIA== X-Received: by 2002:a05:6402:6:: with SMTP id d6mr1567340edu.236.1626131259232; Mon, 12 Jul 2021 16:07:39 -0700 (PDT) Received: from msft-t490s.fritz.box (host-95-250-115-52.retail.telecomitalia.it. [95.250.115.52]) by smtp.gmail.com with ESMTPSA id h3sm5494111ejf.53.2021.07.12.16.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 16:07:38 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig 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 , JeffleXu Subject: [PATCH v5 1/6] block: add disk sequence number Date: Tue, 13 Jul 2021 01:05:25 +0200 Message-Id: <20210712230530.29323-2-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712230530.29323-1-mcroce@linux.microsoft.com> References: <20210712230530.29323-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Matteo Croce Associating uevents with block devices in userspace is difficult and racy: the uevent netlink socket is lossy, and on slow and overloaded systems has a very high latency. Block devices do not have exclusive owners in userspace, any process can set one up (e.g. loop devices). Moreover, device names can be reused (e.g. loop0 can be reused again and again). A userspace process setting up a block device and watching for its events cannot thus reliably tell whether an event relates to the device it just set up or another earlier instance with the same name. Being able to set a UUID on a loop device would solve the race conditions. But it does not allow to derive orderings from uevents: if you see a uevent with a UUID that does not match the device you are waiting for, you cannot tell whether it's because the right uevent has not arrived yet, or it was already sent and you missed it. So you cannot tell whether you should wait for it or not. Associating a unique, monotonically increasing sequential number to the lifetime of each block device, which can be retrieved with an ioctl immediately upon setting it up, allows to solve the race conditions with uevents, and also allows userspace processes to know whether they should wait for the uevent they need or if it was dropped and thus they should move on. Additionally, increment the disk sequence number when the media change, i.e. on DISK_EVENT_MEDIA_CHANGE event. Reviewed-by: Christoph Hellwig Signed-off-by: Matteo Croce --- block/disk-events.c | 3 +++ block/genhd.c | 24 ++++++++++++++++++++++++ include/linux/genhd.h | 2 ++ 3 files changed, 29 insertions(+) diff --git a/block/disk-events.c b/block/disk-events.c index a75931ff5da4..04c52f3992ed 100644 --- a/block/disk-events.c +++ b/block/disk-events.c @@ -190,6 +190,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 diff --git a/block/genhd.c b/block/genhd.c index af4d2ab4a633..0be32dbe97bb 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -29,6 +29,23 @@ static struct kobject *block_depr; +/* + * Unique, monotonically increasing sequential number associated with block + * devices instances (i.e. incremented each time a device is attached). + * Associating uevents with block devices in userspace is difficult and racy: + * the uevent netlink socket is lossy, and on slow and overloaded systems has + * a very high latency. + * Block devices do not have exclusive owners in userspace, any process can set + * one up (e.g. loop devices). Moreover, device names can be reused (e.g. loop0 + * can be reused again and again). + * A userspace process setting up a block device and watching for its events + * cannot thus reliably tell whether an event relates to the device it just set + * up or another earlier instance with the same name. + * This sequential number allows userspace processes to solve this problem, and + * uniquely associate an uevent to the lifetime to a device. + */ +static atomic64_t diskseq; + /* for extended dynamic devt allocation, currently only one major is used */ #define NR_EXT_DEVT (1 << MINORBITS) static DEFINE_IDA(ext_devt_ida); @@ -1263,6 +1280,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: @@ -1363,3 +1382,8 @@ int bdev_read_only(struct block_device *bdev) return bdev->bd_read_only || get_disk_ro(bdev->bd_disk); } EXPORT_SYMBOL(bdev_read_only); + +void inc_diskseq(struct gendisk *disk) +{ + disk->diskseq = atomic64_inc_return(&diskseq); +} diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 13b34177cc85..140c028845af 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -172,6 +172,7 @@ struct gendisk { int node_id; struct badblocks *bb; struct lockdep_map lockdep_map; + u64 diskseq; }; /* @@ -332,6 +333,7 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev, #endif /* CONFIG_SYSFS */ dev_t part_devt(struct gendisk *disk, u8 partno); +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 Mon Jul 12 23:05:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12372541 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,URIBL_BLOCKED,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 272C8C07E99 for ; Mon, 12 Jul 2021 23:07:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C89E60FD8 for ; Mon, 12 Jul 2021 23:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbhGLXKc (ORCPT ); Mon, 12 Jul 2021 19:10:32 -0400 Received: from mail-ed1-f44.google.com ([209.85.208.44]:39901 "EHLO mail-ed1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232724AbhGLXKc (ORCPT ); Mon, 12 Jul 2021 19:10:32 -0400 Received: by mail-ed1-f44.google.com with SMTP id v1so30439901edt.6; Mon, 12 Jul 2021 16:07:41 -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=DWKRBp3AChwDUw/Y1iiOPEb3yfZHMHAFp5fo3Bbvlxw=; b=uiFLVBKVC6AuAiVljPf3WoK2Oe5OJ54g0h8o4kkbfPy76BfDjqxR2k/rUAO8HtDvLu tcqLhr54Tzo09y7uSQkdgO9Kt++0O/ut34Ts6YM228k8I1KobbPJmq9ASIph+WncrzJZ B9OCJ2/BbfC0NUznx5wuslZD9jTVqlr4TWPBFxYDNalT1B27p+B5mmE7+YXjfc8i99iD /IFn8pNxM4LbnHWtJC/D7fnkbD6Ne+iSNUr2zMyDgnznM5CNKyrbK6DBMKdWXNd1eUNr +d6Jb4xVwTBuLk1o0LCvhXno91KEFrMcrSq1hu6sLpnsCZ8P4lewJSVC4W1Y7MkvM4vL Fo2Q== X-Gm-Message-State: AOAM5326ivdwZ8najb67YZdclfupOU5eCLv9WFpjJ9HfnPSfJ5LXDpfF XFcmRqX0ZiUhvW4H57HppdqfzNILv3c3PQ== X-Google-Smtp-Source: ABdhPJymSzPj+Az1K63HfDN4fcrNSw5JyvoykWC+eG/BdMBuhVKvQumZLxfBdQqx0D3ct1cde4ePpA== X-Received: by 2002:a05:6402:2044:: with SMTP id bc4mr1568620edb.307.1626131260968; Mon, 12 Jul 2021 16:07:40 -0700 (PDT) Received: from msft-t490s.fritz.box (host-95-250-115-52.retail.telecomitalia.it. [95.250.115.52]) by smtp.gmail.com with ESMTPSA id h3sm5494111ejf.53.2021.07.12.16.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 16:07:40 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig 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 , JeffleXu Subject: [PATCH v5 2/6] block: export the diskseq in uevents Date: Tue, 13 Jul 2021 01:05:26 +0200 Message-Id: <20210712230530.29323-3-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712230530.29323-1-mcroce@linux.microsoft.com> References: <20210712230530.29323-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Matteo Croce Export the newly introduced diskseq in uevents: $ 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 Reviewed-by: Christoph Hellwig Signed-off-by: Matteo Croce --- block/genhd.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 0be32dbe97bb..3126f8afe3b8 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1101,8 +1101,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, From patchwork Mon Jul 12 23:05:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12372543 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,URIBL_BLOCKED,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 2E2FCC07E9C for ; Mon, 12 Jul 2021 23:07:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1432D60E0B for ; Mon, 12 Jul 2021 23:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233025AbhGLXKe (ORCPT ); Mon, 12 Jul 2021 19:10:34 -0400 Received: from mail-ej1-f52.google.com ([209.85.218.52]:40750 "EHLO mail-ej1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232911AbhGLXKe (ORCPT ); Mon, 12 Jul 2021 19:10:34 -0400 Received: by mail-ej1-f52.google.com with SMTP id o5so37814174ejy.7; Mon, 12 Jul 2021 16:07:43 -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=Y3koryDaOA6/9bcI8unsx1MLaBEFywHb4rwejNyG6tE=; b=odebTodqIjSudgZ0wWn8mRhvv5EVtcwMGyLnxA+BsQFqG8z+uyz+x7KJWGag9AAgpW qyZn+WaC9Hwvpb6pR7fCLaH++Q4Vv5mBIogvpVq+ol3DPLaWUajFlj0OgBc+DmlNI2VR 2eizfAbjAs3J0K+IT7sc3ev9kX5fu26mGHPtbzcrWfe0Sq1063EQWvRCuAWR9uYKL5Mr uDo2OX2cpyMuIhNl272O5hIGLmBtHxU6mwV8e3oRwNqsGnfTAnvNg3t0CHXF6kdrnX2g OsDNyw+QNbkE5RAcAm11GZinZLs0xLlvRxlGlVodwBwmZiAAVQ464awq053fhfL9pctL 6y3w== X-Gm-Message-State: AOAM531JtsunR/NIcqWW7idFutKXHhx/9if4OCfDZ9XOzORhy32N20S7 DLR71t9jD/LF/rE1AfYbRbgUsmrj40CvGg== X-Google-Smtp-Source: ABdhPJy4+ONUDQ4nc4RpW8p+lt4JGKTRBN+97WTCckeOjf7aHhhjhSKQulegxLC/YoP1FRZxBqzTEA== X-Received: by 2002:a17:907:7d8b:: with SMTP id oz11mr1714569ejc.143.1626131262696; Mon, 12 Jul 2021 16:07:42 -0700 (PDT) Received: from msft-t490s.fritz.box (host-95-250-115-52.retail.telecomitalia.it. [95.250.115.52]) by smtp.gmail.com with ESMTPSA id h3sm5494111ejf.53.2021.07.12.16.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 16:07:42 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig 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 , JeffleXu Subject: [PATCH v5 3/6] block: add ioctl to read the disk sequence number Date: Tue, 13 Jul 2021 01:05:27 +0200 Message-Id: <20210712230530.29323-4-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712230530.29323-1-mcroce@linux.microsoft.com> References: <20210712230530.29323-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@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 Reviewed-by: Christoph Hellwig 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 24beec9ca9c9..0c3a4a53fa11 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 Mon Jul 12 23:05:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12372545 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,URIBL_BLOCKED,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 8E63FC07E99 for ; Mon, 12 Jul 2021 23:07:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D80560C40 for ; Mon, 12 Jul 2021 23:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232911AbhGLXKg (ORCPT ); Mon, 12 Jul 2021 19:10:36 -0400 Received: from mail-ej1-f49.google.com ([209.85.218.49]:47068 "EHLO mail-ej1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232724AbhGLXKf (ORCPT ); Mon, 12 Jul 2021 19:10:35 -0400 Received: by mail-ej1-f49.google.com with SMTP id c17so37697566ejk.13; Mon, 12 Jul 2021 16:07:45 -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=EvP6Fne4aXdnLMlil8UuaLMPcQSUTlS5a68+UjZbj8g=; b=R1+Np6xeQIQCyf++wiome/TkCh59O6XyRW9kg+WTgqflJ2grjXSsJfnQ361CDWdFK2 CMD7XyvKMfq+7no5Czlyhvb3OG9xsTCTKa9eX28LK8YWC9GrbEUioTjiokoS6UeaMGrw ye9LMPMTQh+SA/RzH03GEFLoAjeGEZ5jJx4xex8SwcIFcdn+KzsY7Q0CbdXg++oIU1nY GNliyvKV/G3hzt2XqaKLmuFsVwdta1eszBs4p9H9fe1hwjAosKgg3OP/DeZ+DiwP5V3b QqKCyarYLwDIo3CzpUYC8sBOzwqmrK8ZGc3bn9frEh40m8w8IaRX93akne5kBIMhBpOw nGwA== X-Gm-Message-State: AOAM532xlfp3bmU+waQD1okxYUiVCsN3TZ6Y5Zvz46ehJfifZV3UP7tD GC0ST4CsdED/t28qnI2akjK3lVZ2zZvlGA== X-Google-Smtp-Source: ABdhPJwQx8VJBFr6xyCr8gxRNQuBUZzI8SkiDSzg72KVBGzMjm06uqXR5ehYK7VlhmEFRh8ofZO9ig== X-Received: by 2002:a17:906:a18b:: with SMTP id s11mr1783529ejy.8.1626131264326; Mon, 12 Jul 2021 16:07:44 -0700 (PDT) Received: from msft-t490s.fritz.box (host-95-250-115-52.retail.telecomitalia.it. [95.250.115.52]) by smtp.gmail.com with ESMTPSA id h3sm5494111ejf.53.2021.07.12.16.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 16:07:43 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig 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 , JeffleXu Subject: [PATCH v5 4/6] block: export diskseq in sysfs Date: Tue, 13 Jul 2021 01:05:28 +0200 Message-Id: <20210712230530.29323-5-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712230530.29323-1-mcroce@linux.microsoft.com> References: <20210712230530.29323-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@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 Reviewed-by: Christoph Hellwig Signed-off-by: Matteo Croce --- Documentation/ABI/testing/sysfs-block | 12 ++++++++++++ block/genhd.c | 10 ++++++++++ 2 files changed, 22 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 3126f8afe3b8..9ac41500caf9 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -985,6 +985,14 @@ static ssize_t disk_discard_alignment_show(struct device *dev, return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue)); } +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 DEVICE_ATTR(range, 0444, disk_range_show, NULL); static DEVICE_ATTR(ext_range, 0444, disk_ext_range_show, NULL); static DEVICE_ATTR(removable, 0444, disk_removable_show, NULL); @@ -997,6 +1005,7 @@ static DEVICE_ATTR(capability, 0444, disk_capability_show, NULL); static DEVICE_ATTR(stat, 0444, part_stat_show, NULL); static DEVICE_ATTR(inflight, 0444, part_inflight_show, NULL); static DEVICE_ATTR(badblocks, 0644, disk_badblocks_show, disk_badblocks_store); +static DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL); #ifdef CONFIG_FAIL_MAKE_REQUEST ssize_t part_fail_show(struct device *dev, @@ -1042,6 +1051,7 @@ static struct attribute *disk_attrs[] = { &dev_attr_events.attr, &dev_attr_events_async.attr, &dev_attr_events_poll_msecs.attr, + &dev_attr_diskseq.attr, #ifdef CONFIG_FAIL_MAKE_REQUEST &dev_attr_fail.attr, #endif From patchwork Mon Jul 12 23:05:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12372547 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,URIBL_BLOCKED,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 1FBC1C07E9C for ; Mon, 12 Jul 2021 23:07:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D44760FF2 for ; Mon, 12 Jul 2021 23:07:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233312AbhGLXKh (ORCPT ); Mon, 12 Jul 2021 19:10:37 -0400 Received: from mail-ed1-f47.google.com ([209.85.208.47]:33614 "EHLO mail-ed1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233172AbhGLXKg (ORCPT ); Mon, 12 Jul 2021 19:10:36 -0400 Received: by mail-ed1-f47.google.com with SMTP id dj21so10585481edb.0; Mon, 12 Jul 2021 16:07:46 -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=ML00JtYVZe2p5B4UKUBPuWY2pChVUASw+imUnUQ2KK0=; b=EsIY/wXXWxiHnRUDSwGxSYUvW9DtOJphpy/RoiVBplRnCmZg4JPhF23rOO6thkSHQL QeDLQWIPJ4swgWj/IYqhyrdW7Dppv7I9i0cgK3stM99EADJoQMwDyfXbH1jyV7+PVBNF Ndgqos9ot7iP/VZ19xp0BOLjg2GXA2ZILx+cvHc4tnby2QQuTVj82g+vk1YTzlObnKqG NVH/Ob5AMselD50b6+oofuXICXg7SEXak7i7KPrxyPH1gkeeN68XgHzYYvw0dRXswcFE QAmVxJ+UboX6kFXOJWnPNWkTOPHWvh4RTW++08mXJ+EesXs2sZtAwUfTr5nYmWABWwjf avIA== X-Gm-Message-State: AOAM5310tUoXdtyl5Rg7HFP3dWrDDdJQxCmPgYQWGEEAhPU1Owqjz+X/ ASG+Kgo3JNa1QoNZH5YrwRcnPihyudHsZw== X-Google-Smtp-Source: ABdhPJww3SzAjyJFWMF5nuYDt8E0J6plzstysO66PJdByEdsTKphpgwbCfxRtBfp/K4GEbFnf4yKJw== X-Received: by 2002:aa7:cd5a:: with SMTP id v26mr1512917edw.287.1626131266117; Mon, 12 Jul 2021 16:07:46 -0700 (PDT) Received: from msft-t490s.fritz.box (host-95-250-115-52.retail.telecomitalia.it. [95.250.115.52]) by smtp.gmail.com with ESMTPSA id h3sm5494111ejf.53.2021.07.12.16.07.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 16:07:45 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig 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 , JeffleXu Subject: [PATCH v5 5/6] block: add a helper to raise a media changed event Date: Tue, 13 Jul 2021 01:05:29 +0200 Message-Id: <20210712230530.29323-6-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712230530.29323-1-mcroce@linux.microsoft.com> References: <20210712230530.29323-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Matteo Croce Refactor disk_check_events() and move some code into disk_event_uevent(). Then add disk_force_media_change(), a helper which will be used by devices to force issuing a DISK_EVENT_MEDIA_CHANGE event. Co-developed-by: Christoph Hellwig Signed-off-by: Christoph Hellwig Signed-off-by: Matteo Croce --- block/disk-events.c | 61 ++++++++++++++++++++++++++++++++----------- include/linux/genhd.h | 1 + 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/block/disk-events.c b/block/disk-events.c index 04c52f3992ed..7445b8ff2775 100644 --- a/block/disk-events.c +++ b/block/disk-events.c @@ -163,15 +163,31 @@ void disk_flush_events(struct gendisk *disk, unsigned int mask) spin_unlock_irq(&ev->lock); } +/* + * Tell userland about new events. Only the events listed in @disk->events are + * reported, and only if DISK_EVENT_FLAG_UEVENT is set. Otherwise, events are + * processed internally but never get reported to userland. + */ +static void disk_event_uevent(struct gendisk *disk, unsigned int events) +{ + char *envp[ARRAY_SIZE(disk_uevents) + 1] = { }; + int nr_events = 0, i; + + for (i = 0; i < ARRAY_SIZE(disk_uevents); i++) + if (events & disk->events & (1 << i)) + envp[nr_events++] = disk_uevents[i]; + + if (nr_events) + kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp); +} + static void disk_check_events(struct disk_events *ev, unsigned int *clearing_ptr) { struct gendisk *disk = ev->disk; - char *envp[ARRAY_SIZE(disk_uevents) + 1] = { }; unsigned int clearing = *clearing_ptr; unsigned int events; unsigned long intv; - int nr_events = 0, i; /* check events */ events = disk->fops->check_events(disk, clearing); @@ -193,19 +209,8 @@ static void disk_check_events(struct disk_events *ev, 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 - * is set. Otherwise, events are processed internally but never - * get reported to userland. - */ - for (i = 0; i < ARRAY_SIZE(disk_uevents); i++) - if ((events & disk->events & (1 << i)) && - (disk->event_flags & DISK_EVENT_FLAG_UEVENT)) - envp[nr_events++] = disk_uevents[i]; - - if (nr_events) - kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp); + if (disk->event_flags & DISK_EVENT_FLAG_UEVENT) + disk_event_uevent(disk, events); } /** @@ -284,6 +289,32 @@ bool bdev_check_media_change(struct block_device *bdev) } EXPORT_SYMBOL(bdev_check_media_change); +/** + * disk_force_media_change - force a media change event + * @disk: the disk which will raise the event + * @events: the events to raise + * + * Generate uevents for the disk. If DISK_EVENT_MEDIA_CHANGE is present, + * attempt to free all dentries and inodes and invalidates all block + * device page cache entries in that case. + * + * Returns %true if DISK_EVENT_MEDIA_CHANGE was raised, or %false if not. + */ +bool disk_force_media_change(struct gendisk *disk, unsigned int events) +{ + disk_event_uevent(disk, events); + + if (!(events & DISK_EVENT_MEDIA_CHANGE)) + return false; + + if (__invalidate_device(disk->part0, true)) + pr_warn("VFS: busy inodes on changed media %s\n", + disk->disk_name); + set_bit(GD_NEED_PART_SCAN, &disk->state); + return true; +} +EXPORT_SYMBOL_GPL(disk_force_media_change); + /* * Separate this part out so that a different pointer for clearing_ptr can be * passed in for disk_clear_events. diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 140c028845af..849486de81c6 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -237,6 +237,7 @@ extern void disk_block_events(struct gendisk *disk); extern void disk_unblock_events(struct gendisk *disk); extern void disk_flush_events(struct gendisk *disk, unsigned int mask); bool set_capacity_and_notify(struct gendisk *disk, sector_t size); +bool disk_force_media_change(struct gendisk *disk, unsigned int events); /* drivers/char/random.c */ extern void add_disk_randomness(struct gendisk *disk) __latent_entropy; From patchwork Mon Jul 12 23:05:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12372549 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 83DCBC11F69 for ; Mon, 12 Jul 2021 23:07:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C9F561008 for ; Mon, 12 Jul 2021 23:07:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233399AbhGLXKj (ORCPT ); Mon, 12 Jul 2021 19:10:39 -0400 Received: from mail-ej1-f41.google.com ([209.85.218.41]:37559 "EHLO mail-ej1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233227AbhGLXKi (ORCPT ); Mon, 12 Jul 2021 19:10:38 -0400 Received: by mail-ej1-f41.google.com with SMTP id i20so37789247ejw.4; Mon, 12 Jul 2021 16:07: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=yDu7kpWtoefW5J8ZIKzJkCaSnNc2E9IfezCix3rW6U0=; b=P6QAbFR5ecW3UgzPTh86y657LQzeb4DvEaO+z0iH9BWnvUElPHelfP0aZnMNU6hS0k +TpqaQm5tneQZoNXwW2qzk3zcicAnGW8P7GC0lcK2UazEkhGefv79JEQpgOj+kHSiET+ pqmBacw3ma2+87JxzqS6XQZPhmSmyTRE4e0HOUG0TunQWZzpZQlIvfKzEjDOo8ExePkB pkIemog3s9O4cLLJf3nSm+VZVjhU32tMkUWsUhD0js4YCrRK3HE/rRjDcmDzYMK2jDbo 05MEOS/OWdjFGb6dkSo0w2ck7tQE8Hd6L1QeiJwNp0F1DtZLRunc0bPvAn/tVYX+YXVi owuw== X-Gm-Message-State: AOAM530a7Pn5VQ6yLBa30Iaqx9Ia7ABEM9jTVjv9rZsh9nH0W0nI8oOz Ze3UesvBU0KqiP0vnSXOoysdYG2rAr+mBA== X-Google-Smtp-Source: ABdhPJzuwVlDk6fjItU6Bzwexmhey6CpWcb7GumzRR2SX43H76HUPpDoB99GJj1ZCYhtsLJ27mLTxg== X-Received: by 2002:a17:907:d89:: with SMTP id go9mr1713628ejc.165.1626131267691; Mon, 12 Jul 2021 16:07:47 -0700 (PDT) Received: from msft-t490s.fritz.box (host-95-250-115-52.retail.telecomitalia.it. [95.250.115.52]) by smtp.gmail.com with ESMTPSA id h3sm5494111ejf.53.2021.07.12.16.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 16:07:47 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe , Christoph Hellwig 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 , JeffleXu Subject: [PATCH v5 6/6] loop: raise media_change event Date: Tue, 13 Jul 2021 01:05:30 +0200 Message-Id: <20210712230530.29323-7-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712230530.29323-1-mcroce@linux.microsoft.com> References: <20210712230530.29323-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Matteo Croce Make the loop device raise a DISK_MEDIA_CHANGE event on attach or detach. # udevadm monitor -up |grep -e DISK_MEDIA_CHANGE -e DEVNAME & # losetup -f zero [ 7.454235] loop0: detected capacity change from 0 to 16384 DISK_MEDIA_CHANGE=1 DEVNAME=/dev/loop0 DEVNAME=/dev/loop0 DEVNAME=/dev/loop0 # losetup -f zero [ 10.205245] loop1: detected capacity change from 0 to 16384 DISK_MEDIA_CHANGE=1 DEVNAME=/dev/loop1 DEVNAME=/dev/loop1 DEVNAME=/dev/loop1 # losetup -f zero2 [ 13.532368] loop2: detected capacity change from 0 to 40960 DISK_MEDIA_CHANGE=1 DEVNAME=/dev/loop2 DEVNAME=/dev/loop2 # losetup -D DEVNAME=/dev/loop1 DISK_MEDIA_CHANGE=1 DEVNAME=/dev/loop1 DEVNAME=/dev/loop2 DISK_MEDIA_CHANGE=1 DEVNAME=/dev/loop2 DEVNAME=/dev/loop0 DISK_MEDIA_CHANGE=1 DEVNAME=/dev/loop0 Signed-off-by: Matteo Croce Reviewed-by: Christoph Hellwig --- drivers/block/loop.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index f37b9e3d833c..f562609b6d53 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -731,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, goto out_err; /* and ... switch */ + disk_force_media_change(lo->lo_disk, DISK_EVENT_MEDIA_CHANGE); blk_mq_freeze_queue(lo->lo_queue); mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); lo->lo_backing_file = file; @@ -1205,6 +1206,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, goto out_unlock; } + disk_force_media_change(lo->lo_disk, DISK_EVENT_MEDIA_CHANGE); set_disk_ro(lo->lo_disk, (lo->lo_flags & LO_FLAGS_READ_ONLY) != 0); INIT_WORK(&lo->rootcg_work, loop_rootcg_workfn); @@ -1349,6 +1351,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) partscan = lo->lo_flags & LO_FLAGS_PARTSCAN && bdev; lo_number = lo->lo_number; + disk_force_media_change(lo->lo_disk, DISK_EVENT_MEDIA_CHANGE); out_unlock: mutex_unlock(&lo->lo_mutex); if (partscan) { @@ -2325,6 +2328,8 @@ static int loop_add(int i) disk->fops = &lo_fops; disk->private_data = lo; disk->queue = lo->lo_queue; + disk->events = DISK_EVENT_MEDIA_CHANGE; + disk->event_flags = DISK_EVENT_FLAG_UEVENT; sprintf(disk->disk_name, "loop%d", i); add_disk(disk); mutex_unlock(&loop_ctl_mutex);