linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: hide badblocks attribute by default
@ 2017-04-27 21:46 Dan Williams
  2017-04-27 23:12 ` Verma, Vishal L
  2017-04-28 14:27 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Williams @ 2017-04-27 21:46 UTC (permalink / raw)
  To: axboe
  Cc: linux-block, Vishal Verma, Christoph Hellwig, Martin K. Petersen,
	linux-kernel

Commit 99e6608c9e74 "block: Add badblock management for gendisks"
allowed for drivers like pmem and software-raid to advertise a list of
bad media areas. However, it inadvertently added a 'badblocks' to all
block devices. Lets clean this up by having the 'badblocks' attribute
not be visible when the driver has not populated a 'struct badblocks'
instance in the gendisk.

Cc: Jens Axboe <axboe@fb.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Reported-by: Vishal Verma <vishal.l.verma@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 block/genhd.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/block/genhd.c b/block/genhd.c
index a9c516a8b37d..12acd48e1210 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1060,8 +1060,19 @@ static struct attribute *disk_attrs[] = {
 	NULL
 };
 
+static umode_t disk_visible(struct kobject *kobj, struct attribute *a, int n)
+{
+	struct device *dev = container_of(kobj, typeof(*dev), kobj);
+	struct gendisk *disk = dev_to_disk(dev);
+
+	if (a == &dev_attr_badblocks.attr && !disk->bb)
+		return 0;
+	return a->mode;
+}
+
 static struct attribute_group disk_attr_group = {
 	.attrs = disk_attrs,
+	.is_visible = disk_visible,
 };
 
 static const struct attribute_group *disk_attr_groups[] = {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: hide badblocks attribute by default
  2017-04-27 21:46 [PATCH] block: hide badblocks attribute by default Dan Williams
@ 2017-04-27 23:12 ` Verma, Vishal L
  2017-04-28 14:27 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Verma, Vishal L @ 2017-04-27 23:12 UTC (permalink / raw)
  To: Williams, Dan J, axboe; +Cc: hch, linux-kernel, linux-block, martin.petersen

On Thu, 2017-04-27 at 14:46 -0700, Dan Williams wrote:
> Commit 99e6608c9e74 "block: Add badblock management for gendisks"
> allowed for drivers like pmem and software-raid to advertise a list of
> bad media areas. However, it inadvertently added a 'badblocks' to all
> block devices. Lets clean this up by having the 'badblocks' attribute
> not be visible when the driver has not populated a 'struct badblocks'
> instance in the gendisk.
> 
> Cc: Jens Axboe <axboe@fb.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Reported-by: Vishal Verma <vishal.l.verma@intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  block/genhd.c |   11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
Tested that this removes the badblocks attribute for block devices that
don't use them:

$ cat /sys/block/pmem6/badblocks 
61576 8

$ cat /sys/block/vda/badblocks 
cat: /sys/block/vda/badblocks: No such file or directory

Tested-by: Vishal Verma <vishal.l.verma@intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] block: hide badblocks attribute by default
  2017-04-27 21:46 [PATCH] block: hide badblocks attribute by default Dan Williams
  2017-04-27 23:12 ` Verma, Vishal L
@ 2017-04-28 14:27 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2017-04-28 14:27 UTC (permalink / raw)
  To: Dan Williams
  Cc: linux-block, Vishal Verma, Christoph Hellwig, Martin K. Petersen,
	linux-kernel

On Thu, Apr 27 2017, Dan Williams wrote:
> Commit 99e6608c9e74 "block: Add badblock management for gendisks"
> allowed for drivers like pmem and software-raid to advertise a list of
> bad media areas. However, it inadvertently added a 'badblocks' to all
> block devices. Lets clean this up by having the 'badblocks' attribute
> not be visible when the driver has not populated a 'struct badblocks'
> instance in the gendisk.

Thanks Dan, added.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-28 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-27 21:46 [PATCH] block: hide badblocks attribute by default Dan Williams
2017-04-27 23:12 ` Verma, Vishal L
2017-04-28 14:27 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).