nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] ndctl, monitor: fix monitor can be started though no dimm event to monitor
@ 2018-07-19  8:54 QI Fuli
  2018-07-19 18:07 ` Verma, Vishal L
  0 siblings, 1 reply; 2+ messages in thread
From: QI Fuli @ 2018-07-19  8:54 UTC (permalink / raw)
  To: linux-nvdimm

Currently, the monitor still can be started though there is no dimm event
to be monitored, which is caused by the typo of uses. In this case,
no smart event message can be logged.
This patch is used to fix this bug. When user starts the monitor with
invalid dimm event in [--dimm-event] option, the monitor will stop and
output error message.

Signed-off-by: QI Fuli <qi.fuli@jp.fujitsu.com>
---
 ndctl/monitor.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/ndctl/monitor.c b/ndctl/monitor.c
index 8300250..abab45f 100644
--- a/ndctl/monitor.c
+++ b/ndctl/monitor.c
@@ -413,7 +413,7 @@ static int monitor_event(struct ndctl_ctx *ctx,
 	return 0;
 }
 
-static int parse_monitor_event(struct monitor *_monitor)
+static int parse_monitor_event(struct monitor *_monitor, struct ndctl_ctx *ctx)
 {
 	char *dimm_event, *save;
 	const char *event;
@@ -432,14 +432,18 @@ static int parse_monitor_event(struct monitor *_monitor)
 		}
 		if (strcmp(event, "dimm-spares-remaining") == 0)
 			_monitor->event_flags |= ND_EVENT_SPARES_REMAINING;
-		if (strcmp(event, "dimm-media-temperature") == 0)
+		else if (strcmp(event, "dimm-media-temperature") == 0)
 			_monitor->event_flags |= ND_EVENT_MEDIA_TEMPERATURE;
-		if (strcmp(event, "dimm-controller-temperature") == 0)
+		else if (strcmp(event, "dimm-controller-temperature") == 0)
 			_monitor->event_flags |= ND_EVENT_CTRL_TEMPERATURE;
-		if (strcmp(event, "dimm-health-state") == 0)
+		else if (strcmp(event, "dimm-health-state") == 0)
 			_monitor->event_flags |= ND_EVENT_HEALTH_STATE;
-		if (strcmp(event, "dimm-unclean-shutdown") == 0)
+		else if (strcmp(event, "dimm-unclean-shutdown") == 0)
 			_monitor->event_flags |= ND_EVENT_UNCLEAN_SHUTDOWN;
+		else {
+			err(ctx, "no dimm-event named %s\n", event);
+			return 1;
+		}
 	}
 
 	free(dimm_event);
@@ -620,7 +624,7 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
 		notice((struct ndctl_ctx *)ctx, "ndctl monitor daemon started\n");
 	}
 
-	if (parse_monitor_event(&monitor))
+	if (parse_monitor_event(&monitor, (struct ndctl_ctx *)ctx))
 		goto out;
 
 	fctx.filter_bus = filter_bus;
-- 
2.18.0


_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [PATCH] ndctl, monitor: fix monitor can be started though no dimm event to monitor
  2018-07-19  8:54 [PATCH] ndctl, monitor: fix monitor can be started though no dimm event to monitor QI Fuli
@ 2018-07-19 18:07 ` Verma, Vishal L
  0 siblings, 0 replies; 2+ messages in thread
From: Verma, Vishal L @ 2018-07-19 18:07 UTC (permalink / raw)
  To: linux-nvdimm, qi.fuli


On Thu, 2018-07-19 at 17:54 +0900, QI Fuli wrote:
> Currently, the monitor still can be started though there is no dimm event
> to be monitored, which is caused by the typo of uses. In this case,
> no smart event message can be logged.
> This patch is used to fix this bug. When user starts the monitor with
> invalid dimm event in [--dimm-event] option, the monitor will stop and
> output error message.
> 
> Signed-off-by: QI Fuli <qi.fuli@jp.fujitsu.com>
> ---
>  ndctl/monitor.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)

Looks good, applied.

> 
> diff --git a/ndctl/monitor.c b/ndctl/monitor.c
> index 8300250..abab45f 100644
> --- a/ndctl/monitor.c
> +++ b/ndctl/monitor.c
> @@ -413,7 +413,7 @@ static int monitor_event(struct ndctl_ctx *ctx,
>  	return 0;
>  }
>  
> -static int parse_monitor_event(struct monitor *_monitor)
> +static int parse_monitor_event(struct monitor *_monitor, struct ndctl_ctx *ctx)
>  {
>  	char *dimm_event, *save;
>  	const char *event;
> @@ -432,14 +432,18 @@ static int parse_monitor_event(struct monitor *_monitor)
>  		}
>  		if (strcmp(event, "dimm-spares-remaining") == 0)
>  			_monitor->event_flags |= ND_EVENT_SPARES_REMAINING;
> -		if (strcmp(event, "dimm-media-temperature") == 0)
> +		else if (strcmp(event, "dimm-media-temperature") == 0)
>  			_monitor->event_flags |= ND_EVENT_MEDIA_TEMPERATURE;
> -		if (strcmp(event, "dimm-controller-temperature") == 0)
> +		else if (strcmp(event, "dimm-controller-temperature") == 0)
>  			_monitor->event_flags |= ND_EVENT_CTRL_TEMPERATURE;
> -		if (strcmp(event, "dimm-health-state") == 0)
> +		else if (strcmp(event, "dimm-health-state") == 0)
>  			_monitor->event_flags |= ND_EVENT_HEALTH_STATE;
> -		if (strcmp(event, "dimm-unclean-shutdown") == 0)
> +		else if (strcmp(event, "dimm-unclean-shutdown") == 0)
>  			_monitor->event_flags |= ND_EVENT_UNCLEAN_SHUTDOWN;
> +		else {
> +			err(ctx, "no dimm-event named %s\n", event);
> +			return 1;
> +		}
>  	}
>  
>  	free(dimm_event);
> @@ -620,7 +624,7 @@ int cmd_monitor(int argc, const char **argv, void *ctx)
>  		notice((struct ndctl_ctx *)ctx, "ndctl monitor daemon started\n");
>  	}
>  
> -	if (parse_monitor_event(&monitor))
> +	if (parse_monitor_event(&monitor, (struct ndctl_ctx *)ctx))
>  		goto out;
>  
>  	fctx.filter_bus = filter_bus;
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2018-07-19 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-19  8:54 [PATCH] ndctl, monitor: fix monitor can be started though no dimm event to monitor QI Fuli
2018-07-19 18:07 ` Verma, Vishal L

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).