Message ID | 20200415130159.611361-13-its@irrelevant.dk |
---|---|
State | New |
Headers | show |
Series | nvme: refactoring and cleanups | expand |
On 4/15/20 3:01 PM, Klaus Jensen wrote: > From: Klaus Jensen <k.jensen@samsung.com> > > Introduce some small helpers to make the next patches easier on the eye. > > Signed-off-by: Klaus Jensen <k.jensen@samsung.com> > --- > hw/block/nvme.c | 3 +-- > hw/block/nvme.h | 16 ++++++++++++++++ > 2 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/hw/block/nvme.c b/hw/block/nvme.c > index 80da0825d295..d5244102252c 100644 > --- a/hw/block/nvme.c > +++ b/hw/block/nvme.c > @@ -1469,8 +1469,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) > id_ns->dps = 0; > id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; > id_ns->ncap = id_ns->nuse = id_ns->nsze = > - cpu_to_le64(n->ns_size >> > - id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); > + cpu_to_le64(nvme_ns_nlbas(n, ns)); Thanks :) Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> > } > } > > diff --git a/hw/block/nvme.h b/hw/block/nvme.h > index 7eecfd3a50f6..dd932a9e7ebc 100644 > --- a/hw/block/nvme.h > +++ b/hw/block/nvme.h > @@ -67,6 +67,17 @@ typedef struct NvmeNamespace { > NvmeIdNs id_ns; > } NvmeNamespace; > > +static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns) > +{ > + NvmeIdNs *id_ns = &ns->id_ns; > + return &id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)]; > +} > + > +static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns) > +{ > + return nvme_ns_lbaf(ns)->ds; > +} > + > #define TYPE_NVME "nvme" > #define NVME(obj) \ > OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME) > @@ -101,4 +112,9 @@ typedef struct NvmeCtrl { > NvmeIdCtrl id_ctrl; > } NvmeCtrl; > > +static inline uint64_t nvme_ns_nlbas(NvmeCtrl *n, NvmeNamespace *ns) > +{ > + return n->ns_size >> nvme_ns_lbads(ns); > +} > + > #endif /* HW_NVME_H */ >
On Wed, 2020-04-15 at 15:01 +0200, Klaus Jensen wrote: > From: Klaus Jensen <k.jensen@samsung.com> > > Introduce some small helpers to make the next patches easier on the eye. > > Signed-off-by: Klaus Jensen <k.jensen@samsung.com> > --- > hw/block/nvme.c | 3 +-- > hw/block/nvme.h | 16 ++++++++++++++++ > 2 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/hw/block/nvme.c b/hw/block/nvme.c > index 80da0825d295..d5244102252c 100644 > --- a/hw/block/nvme.c > +++ b/hw/block/nvme.c > @@ -1469,8 +1469,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) > id_ns->dps = 0; > id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; > id_ns->ncap = id_ns->nuse = id_ns->nsze = > - cpu_to_le64(n->ns_size >> > - id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); > + cpu_to_le64(nvme_ns_nlbas(n, ns)); > } > } > > diff --git a/hw/block/nvme.h b/hw/block/nvme.h > index 7eecfd3a50f6..dd932a9e7ebc 100644 > --- a/hw/block/nvme.h > +++ b/hw/block/nvme.h > @@ -67,6 +67,17 @@ typedef struct NvmeNamespace { > NvmeIdNs id_ns; > } NvmeNamespace; > > +static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns) > +{ > + NvmeIdNs *id_ns = &ns->id_ns; > + return &id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)]; > +} > + > +static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns) > +{ > + return nvme_ns_lbaf(ns)->ds; > +} > + > #define TYPE_NVME "nvme" > #define NVME(obj) \ > OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME) > @@ -101,4 +112,9 @@ typedef struct NvmeCtrl { > NvmeIdCtrl id_ctrl; > } NvmeCtrl; > > +static inline uint64_t nvme_ns_nlbas(NvmeCtrl *n, NvmeNamespace *ns) > +{ > + return n->ns_size >> nvme_ns_lbads(ns); > +} > + > #endif /* HW_NVME_H */ Nitpick: On second thought, these function names do sound quite cryptic, so maybe at least for nvme_ns_nlbas pick something more readable? maybe nvme_ns_number_of_lbas or something. Or add a comment - comment always fixes these kind of issues. But that doesn't matter much IMHO, so Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Best regards, Maxim Levitsky
diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 80da0825d295..d5244102252c 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -1469,8 +1469,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp) id_ns->dps = 0; id_ns->lbaf[0].ds = BDRV_SECTOR_BITS; id_ns->ncap = id_ns->nuse = id_ns->nsze = - cpu_to_le64(n->ns_size >> - id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); + cpu_to_le64(nvme_ns_nlbas(n, ns)); } } diff --git a/hw/block/nvme.h b/hw/block/nvme.h index 7eecfd3a50f6..dd932a9e7ebc 100644 --- a/hw/block/nvme.h +++ b/hw/block/nvme.h @@ -67,6 +67,17 @@ typedef struct NvmeNamespace { NvmeIdNs id_ns; } NvmeNamespace; +static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns) +{ + NvmeIdNs *id_ns = &ns->id_ns; + return &id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)]; +} + +static inline uint8_t nvme_ns_lbads(NvmeNamespace *ns) +{ + return nvme_ns_lbaf(ns)->ds; +} + #define TYPE_NVME "nvme" #define NVME(obj) \ OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME) @@ -101,4 +112,9 @@ typedef struct NvmeCtrl { NvmeIdCtrl id_ctrl; } NvmeCtrl; +static inline uint64_t nvme_ns_nlbas(NvmeCtrl *n, NvmeNamespace *ns) +{ + return n->ns_size >> nvme_ns_lbads(ns); +} + #endif /* HW_NVME_H */