From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 D9DB2C433E6 for ; Tue, 12 Jan 2021 12:45:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5362322B37 for ; Tue, 12 Jan 2021 12:45:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5362322B37 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A64BD8D00A3; Tue, 12 Jan 2021 07:45:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A142D8D0090; Tue, 12 Jan 2021 07:45:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9027E8D00A3; Tue, 12 Jan 2021 07:45:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 744738D0090 for ; Tue, 12 Jan 2021 07:45:55 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 39A811EE6 for ; Tue, 12 Jan 2021 12:45:55 +0000 (UTC) X-FDA: 77697095070.01.hot51_55046b627515 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 19DE410046472 for ; Tue, 12 Jan 2021 12:45:55 +0000 (UTC) X-HE-Tag: hot51_55046b627515 X-Filterd-Recvd-Size: 7336 Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 12:45:51 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.79,341,1602518400"; d="scan'208";a="103404320" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Jan 2021 20:45:45 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id 713454CE602E; Tue, 12 Jan 2021 20:45:40 +0800 (CST) Received: from irides.mr (10.167.225.141) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 12 Jan 2021 20:45:40 +0800 Subject: Re: [PATCH 08/10] md: Implement ->corrupted_range() To: Jan Kara CC: , , , , , , , , , , , , , References: <20201230165601.845024-1-ruansy.fnst@cn.fujitsu.com> <20201230165601.845024-9-ruansy.fnst@cn.fujitsu.com> <20210106171429.GE29271@quack2.suse.cz> From: Ruan Shiyang Message-ID: Date: Tue, 12 Jan 2021 20:45:38 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210106171429.GE29271@quack2.suse.cz> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Language: en-US X-Originating-IP: [10.167.225.141] X-ClientProxiedBy: G08CNEXCHPEKD04.g08.fujitsu.local (10.167.33.200) To G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) X-yoursite-MailScanner-ID: 713454CE602E.AB184 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@cn.fujitsu.com Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2021/1/7 =E4=B8=8A=E5=8D=881:14, Jan Kara wrote: > On Thu 31-12-20 00:55:59, Shiyang Ruan wrote: >> With the support of ->rmap(), it is possible to obtain the superblock = on >> a mapped device. >> >> If a pmem device is used as one target of mapped device, we cannot >> obtain its superblock directly. With the help of SYSFS, the mapped >> device can be found on the target devices. So, we iterate the >> bdev->bd_holder_disks to obtain its mapped device. >> >> Signed-off-by: Shiyang Ruan >=20 > Thanks for the patch. Two comments below. >=20 >> diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c >> index 4688bff19c20..9f9a2f3bf73b 100644 >> --- a/drivers/nvdimm/pmem.c >> +++ b/drivers/nvdimm/pmem.c >> @@ -256,21 +256,16 @@ static int pmem_rw_page(struct block_device *bde= v, sector_t sector, >> static int pmem_corrupted_range(struct gendisk *disk, struct block_d= evice *bdev, >> loff_t disk_offset, size_t len, void *data) >> { >> - struct super_block *sb; >> loff_t bdev_offset; >> sector_t disk_sector =3D disk_offset >> SECTOR_SHIFT; >> - int rc =3D 0; >> + int rc =3D -ENODEV; >> =20 >> bdev =3D bdget_disk_sector(disk, disk_sector); >> if (!bdev) >> - return -ENODEV; >> + return rc; >> =20 >> bdev_offset =3D (disk_sector - get_start_sect(bdev)) << SECTOR_SHIF= T; >> - sb =3D get_super(bdev); >> - if (sb && sb->s_op->corrupted_range) { >> - rc =3D sb->s_op->corrupted_range(sb, bdev, bdev_offset, len, data); >> - drop_super(sb); >> - } >> + rc =3D bd_corrupted_range(bdev, bdev_offset, bdev_offset, len, data)= ; >> =20 >> bdput(bdev); >> return rc; >=20 > This (and the fs/block_dev.c change below) is just refining the functio= n > you've implemented in the patch 6. I think it's confusing to split chan= ges > like this - why not implement things correctly from the start in patch = 6? This change added a helper function to find the md devices created on a=20 low-level block device, such as a LVM on /dev/pmem0, and calls=20 ->corrupted_range() for each md device. The md parts were introduced=20 starts from patch 7. So, I add this change in this patch. >=20 >> diff --git a/fs/block_dev.c b/fs/block_dev.c >> index 9e84b1928b94..0e50f0e8e8af 100644 >> --- a/fs/block_dev.c >> +++ b/fs/block_dev.c >> @@ -1171,6 +1171,27 @@ struct bd_holder_disk { >> int refcnt; >> }; >> =20 >> +static int bd_disk_holder_corrupted_range(struct block_device *bdev, = loff_t off, >> + size_t len, void *data) >> +{ >> + struct bd_holder_disk *holder; >> + struct gendisk *disk; >> + int rc =3D 0; >> + >> + if (list_empty(&(bdev->bd_holder_disks))) >> + return -ENODEV; >=20 > This will not compile for !CONFIG_SYSFS kernels. Not that it would be > common but still. Also I'm not sure whether using bd_holder_disks like = this > is really the right thing to do (when it seems to be only a sysfs thing= ), > although admittedly I'm not aware of a better way of getting this > information. I did a lot of tries and finally found this way. I think I should add a=20 judgement that whether CONFIG_SYSFS is turned on. -- Thanks, Ruan Shiyang. >=20 > Honza >=20 >> + >> + list_for_each_entry(holder, &bdev->bd_holder_disks, list) { >> + disk =3D holder->disk; >> + if (disk->fops->corrupted_range) { >> + rc =3D disk->fops->corrupted_range(disk, bdev, off, len, data); >> + if (rc !=3D -ENODEV) >> + break; >> + } >> + } >> + return rc; >> +} >> + >> static struct bd_holder_disk *bd_find_holder_disk(struct block_devic= e *bdev, >> struct gendisk *disk) >> { >> @@ -1378,6 +1399,22 @@ void bd_set_nr_sectors(struct block_device *bde= v, sector_t sectors) >> } >> EXPORT_SYMBOL(bd_set_nr_sectors); >> =20 >> +int bd_corrupted_range(struct block_device *bdev, loff_t disk_off, lo= ff_t bdev_off, size_t len, void *data) >> +{ >> + struct super_block *sb =3D get_super(bdev); >> + int rc =3D 0; >> + >> + if (!sb) { >> + rc =3D bd_disk_holder_corrupted_range(bdev, disk_off, len, data); >> + return rc; >> + } else if (sb->s_op->corrupted_range) >> + rc =3D sb->s_op->corrupted_range(sb, bdev, bdev_off, len, data); >> + drop_super(sb); >> + >> + return rc; >> +} >> +EXPORT_SYMBOL(bd_corrupted_range); >> + >> static void __blkdev_put(struct block_device *bdev, fmode_t mode, in= t for_part); >> =20 >> int bdev_disk_changed(struct block_device *bdev, bool invalidate) >> diff --git a/include/linux/genhd.h b/include/linux/genhd.h >> index ed06209008b8..42290470810d 100644 >> --- a/include/linux/genhd.h >> +++ b/include/linux/genhd.h >> @@ -376,6 +376,8 @@ void revalidate_disk_size(struct gendisk *disk, bo= ol verbose); >> bool bdev_check_media_change(struct block_device *bdev); >> int __invalidate_device(struct block_device *bdev, bool kill_dirty); >> void bd_set_nr_sectors(struct block_device *bdev, sector_t sectors); >> +int bd_corrupted_range(struct block_device *bdev, loff_t disk_off, >> + loff_t bdev_off, size_t len, void *data); >> =20 >> /* for drivers/char/raw.c: */ >> int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned = long); >> --=20 >> 2.29.2 >> >> >>