Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5556824pxj; Wed, 23 Jun 2021 04:04:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy/u/Iufn3hh6WCyO85YnBuvlcfayNYHgdGGRaZon6eCb8hfaxPIxF7awwKa5RAKPAqMY4 X-Received: by 2002:a05:6402:b7a:: with SMTP id cb26mr11581022edb.184.1624446287173; Wed, 23 Jun 2021 04:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624446287; cv=none; d=google.com; s=arc-20160816; b=sMzAtumRVDY3Sv8YK4f9wQxqGCjLXNZKUH0O922iJQCLCsEoe1czDBmXs4V1Y+K7dJ ziXCfncj3I8f6bF3JHgag/wl2LZ53itZ8gxbieJ66UmzIz0ng7CuCwbE4M77XqAdGwhM 8YzP/2OGAs2KT0ogd+RWHHon0biZrN/3Cgacm2F9QDQfkQ1Qcp9uvgChvCMVryr2k9Fh JzvXWkM/2wSwFJ1OI7dYSE49ZkmcZqwS2yzgVxdQrz/DI6WprrCZm1CIIplFx+VOgP/d 793gAW7lZtxHF3UJYaUWgT6oIx87/mDC44/G6+qob7sBz9/X+tlVkvfCRjjmt+0L5VdW MUkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lIaKl1OxDgMFf5G0f4ixWy1oghSZADo8i4vWnrvSFg8=; b=g1OSWndSZC3kxTunF0JTwA3nH5BSsp3omdakMNDgRY3FAXEi5DTluN7DG7JcN17Cpo CqAcbHUTBFnMQww5ynN6zxAautEbevfPEh5UAdnyNVuxavshAZs7h77i8wancszjFmx7 zbElW0zJ+GYoa1pJBCMKJSQFnMF84eEP0vDKQxvs1URV0dqaFt4Z996lum5UCh+fnyN5 hZ3OxSeuPtRGpJxXJBhHM689CAaPz39XOMhai43FS5/ZgAFpYzlA9cc47IMwA7SWoQH/ Z165i41Jm1PXLDGmNGuq/BynucvABWlSiEuiGJyH74sKCjB9ss5jzEKc4AP3FU4Dr64W hXWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay17si3739814ejb.438.2021.06.23.04.04.24; Wed, 23 Jun 2021 04:04:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230402AbhFWLCb (ORCPT + 99 others); Wed, 23 Jun 2021 07:02:31 -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-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=20Gonz=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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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; -- 2.31.1