File libndctl-msft-Add-custom-cmd_is_supported-method.patch of Package ndctl

From cf85848aa67cc8d222a6566186c1b2af786c2ef1 Mon Sep 17 00:00:00 2001
From: Alexander Motin <mav@ixsystems.com>
Date: Wed, 15 Feb 2023 11:49:32 -0500
Subject: [PATCH 5/6] libndctl/msft: Add custom cmd_is_supported() method

Upstream: v76
Git-commit: cf85848aa67cc8d222a6566186c1b2af786c2ef1

Allow the ndctl-monitor command to work with MSFT family NVDIMMs by
adding a cmd_is_supported() method.

Signed-off-by: Alexander Motin <mav@ixsystems.com>
Link: https://lore.kernel.org/r/20230215164930.707170-3-mav@ixsystems.com
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/lib/msft.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/ndctl/lib/msft.c b/ndctl/lib/msft.c
index b5278c5..b8ef00f 100644
--- a/ndctl/lib/msft.c
+++ b/ndctl/lib/msft.c
@@ -30,6 +30,15 @@ static const char *msft_cmd_desc(int fn)
 	return desc;
 }
 
+static bool msft_cmd_is_supported(struct ndctl_dimm *dimm, int cmd)
+{
+	/* Handle this separately to support monitor mode */
+	if (cmd == ND_CMD_SMART)
+		return true;
+
+	return !!(dimm->cmd_mask & (1ULL << cmd));
+}
+
 static u32 msft_get_firmware_status(struct ndctl_cmd *cmd)
 {
 	return cmd->msft->u.smart.status;
@@ -195,6 +204,7 @@ static int msft_cmd_xlat_firmware_status(struct ndctl_cmd *cmd)
 
 struct ndctl_dimm_ops * const msft_dimm_ops = &(struct ndctl_dimm_ops) {
 	.cmd_desc = msft_cmd_desc,
+	.cmd_is_supported = msft_cmd_is_supported,
 	.new_smart = msft_dimm_cmd_new_smart,
 	.smart_get_flags = msft_cmd_smart_get_flags,
 	.smart_get_health = msft_cmd_smart_get_health,
-- 
2.39.1

openSUSE Build Service is sponsored by