[PATCH] nvme-sysfs: display max_hw_sectors_kb without requiring namespaces
Abhishek Bapat
abhishekbapat at google.com
Thu Oct 17 14:09:51 PDT 2024
On Wed, Oct 16, 2024 at 2:54 PM Prashant Malani <pmalani at google.com> wrote:
>
> Hi Abhishek,
>
>
> On Wed, 16 Oct 2024 at 14:31, Abhishek Bapat <abhishekbapat at google.com> wrote:
> >
> > From: Abhishek <abhishekbapat at google.com>
>
> Here and in the S-o-b line: Please use your full legal name.
Acknowledged.
>
> > diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
> > index b68a9e5f1ea3..1af2b2cf1a6c 100644
> > --- a/drivers/nvme/host/sysfs.c
> > +++ b/drivers/nvme/host/sysfs.c
> > @@ -546,6 +546,17 @@ static ssize_t dctype_show(struct device *dev,
> > }
> > static DEVICE_ATTR_RO(dctype);
> >
> > +static ssize_t max_hw_sectors_kb_show(struct device *dev,
> > + struct device_attribute *attr,
> > + char *buf)
> > +{
> > + struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> > + u32 max_hw_sectors_kb = ctrl->max_hw_sectors >> 1;
>
> In what unit is max_hw_sector stored? If it's "number of sectors", is this
> conversion to size correct, or should SECTOR_SHIFT be used?
The unit for max_hw_sectors is sectors. Left shifting with SECTOR_SHIFT
will change the unit to bytes, and then we will have to right shift by 10
to convert it into KiB. The net effect is right shifting by one as the value
of SECTOR_SHIFT is 9. This programming pattern is used within the
Block layer code as well.
More information about the Linux-nvme
mailing list