On 4/12/24 2:05 PM, Vishal Verma wrote:
> The loop through the provided list of devices in do_xaction_device()
> returns the status based on whatever the last device did. Since the
> order of processing devices, especially in cases like the 'all' keyword,
> can be effectively random, this can lead to the same command, and same
> effects, exiting with a different error code based on device ordering.
>
> This was noticed with flakiness in the daxctl-create.sh unit test. Its
> 'destroy-device all' command would either pass or fail based on the
> order it tried to destroy devices in. (Recall that until now, destroying
> a daxX.0 device would result in a failure).
>
> Make this slightly more consistent by saving a failed status in
> do_xaction_device if any iteration of the loop produces a failure.
> Return this saved status instead of returning the status of the last
> device processed.
>
> Cc: Dan Williams <dan.j.willi...@intel.com>
> Cc: Alison Schofield <alison.schofi...@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.ve...@intel.com>
Reviewed-by: Dave Jiang <dave.ji...@intel.com>
> ---
> daxctl/device.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/daxctl/device.c b/daxctl/device.c
> index 83c61389..14d62148 100644
> --- a/daxctl/device.c
> +++ b/daxctl/device.c
> @@ -1012,7 +1012,7 @@ static int do_xaction_device(const char *device, enum
> device_action action,
> struct json_object *jdevs = NULL;
> struct daxctl_region *region;
> struct daxctl_dev *dev;
> - int rc = -ENXIO;
> + int rc = -ENXIO, saved_rc = 0;
>
> *processed = 0;
>
> @@ -1059,6 +1059,8 @@ static int do_xaction_device(const char *device, enum
> device_action action,
> rc = -EINVAL;
> break;
> }
> + if (rc)
> + saved_rc = rc;
> }
> }
>
> @@ -1070,7 +1072,7 @@ static int do_xaction_device(const char *device, enum
> device_action action,
> if (jdevs)
> util_display_json_array(stdout, jdevs, flags);
>
> - return rc;
> + return saved_rc;
> }
>
> int cmd_create_device(int argc, const char **argv, struct daxctl_ctx *ctx)
>