diff mbox series

[for-7.0,2/4] hw/nvme: add zone attribute get/set helpers

Message ID 20211125073735.248403-3-its@irrelevant.dk (mailing list archive)
State New, archived
Headers show
Series hw/nvme: zoned random write area | expand

Commit Message

Klaus Jensen Nov. 25, 2021, 7:37 a.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

Add some get/set helpers for zone attributes.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c       | 4 ++--
 include/block/nvme.h | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

Comments

Keith Busch Jan. 26, 2022, 5:05 p.m. UTC | #1
On Thu, Nov 25, 2021 at 08:37:33AM +0100, Klaus Jensen wrote:
> @@ -295,7 +295,7 @@ static void nvme_assign_zone_state(NvmeNamespace *ns, NvmeZone *zone,
>      case NVME_ZONE_STATE_READ_ONLY:
>          break;
>      default:
> -        zone->d.za = 0;
> +        NVME_ZA_CLEAR_ALL(zone->d.za);
>      }
>  }
>  
> @@ -3356,7 +3356,7 @@ static uint16_t nvme_set_zd_ext(NvmeNamespace *ns, NvmeZone *zone)
>              return status;
>          }
>          nvme_aor_inc_active(ns);
> -        zone->d.za |= NVME_ZA_ZD_EXT_VALID;
> +        NVME_ZA_SET(zone->d.za, NVME_ZA_ZD_EXT_VALID);
>          nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED);
>          return NVME_SUCCESS;
>      }
> diff --git a/include/block/nvme.h b/include/block/nvme.h
> index 2ee227760265..2b8b906466ab 100644
> --- a/include/block/nvme.h
> +++ b/include/block/nvme.h
> @@ -1407,6 +1407,10 @@ enum NvmeZoneAttr {
>      NVME_ZA_ZD_EXT_VALID             = 1 << 7,
>  };
>  
> +#define NVME_ZA_SET(za, attrs)   ((za) |= (attrs))
> +#define NVME_ZA_CLEAR(za, attrs) ((za) &= ~(attrs))
> +#define NVME_ZA_CLEAR_ALL(za)    ((za) = 0x0)

This doesn't really look any more helpful than open coding it. I think
it would appear better to take a "struct NvmeZone" type parameter
instead, and use inline functions instead of macro.
diff mbox series

Patch

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 489d586ab9d7..7ac6ec50a0d1 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -295,7 +295,7 @@  static void nvme_assign_zone_state(NvmeNamespace *ns, NvmeZone *zone,
     case NVME_ZONE_STATE_READ_ONLY:
         break;
     default:
-        zone->d.za = 0;
+        NVME_ZA_CLEAR_ALL(zone->d.za);
     }
 }
 
@@ -3356,7 +3356,7 @@  static uint16_t nvme_set_zd_ext(NvmeNamespace *ns, NvmeZone *zone)
             return status;
         }
         nvme_aor_inc_active(ns);
-        zone->d.za |= NVME_ZA_ZD_EXT_VALID;
+        NVME_ZA_SET(zone->d.za, NVME_ZA_ZD_EXT_VALID);
         nvme_assign_zone_state(ns, zone, NVME_ZONE_STATE_CLOSED);
         return NVME_SUCCESS;
     }
diff --git a/include/block/nvme.h b/include/block/nvme.h
index 2ee227760265..2b8b906466ab 100644
--- a/include/block/nvme.h
+++ b/include/block/nvme.h
@@ -1407,6 +1407,10 @@  enum NvmeZoneAttr {
     NVME_ZA_ZD_EXT_VALID             = 1 << 7,
 };
 
+#define NVME_ZA_SET(za, attrs)   ((za) |= (attrs))
+#define NVME_ZA_CLEAR(za, attrs) ((za) &= ~(attrs))
+#define NVME_ZA_CLEAR_ALL(za)    ((za) = 0x0)
+
 typedef struct QEMU_PACKED NvmeZoneReportHeader {
     uint64_t    nr_zones;
     uint8_t     rsvd[56];